﻿<UserControl x:Class="HouseKeepingPL.UserControls.AccountControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:pswh="clr-namespace:HouseKeepingPL"
             Name="AccountUserControl"
             Width="auto"
             d:DesignHeight="321"
             d:DesignWidth="511"
             DataContext="{Binding AccountVM,
                                   Source={StaticResource Locator}}"
             mc:Ignorable="d">



    <UserControl.Resources>
        <ControlTemplate x:Key="validationTemplate">
            <DockPanel>
                <Border BorderBrush="Red" BorderThickness="1">
                    <AdornedElementPlaceholder />
                </Border>
                <Border Width="20"
                        Height="20"
                        Margin="5,0,0,0"
                        Background="Red"
                        CornerRadius="10"
                        DockPanel.Dock="right"
                        ToolTip="{Binding ElementName=customAdorner,
                                          Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
                    <TextBlock HorizontalAlignment="center"
                               VerticalAlignment="center"
                               FontSize="20"
                               FontWeight="Bold"
                               Foreground="WhiteSmoke"
                               Text="!!" />
                </Border>
            </DockPanel>
        </ControlTemplate>
        <Style x:Key="MyTabStyle" TargetType="Grid">
            <Setter Property="Background" Value="AliceBlue" />
        </Style>

        <Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="PasswordBoxInError" TargetType="{x:Type PasswordBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="ComboBoxInError" TargetType="{x:Type ComboBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>

    </UserControl.Resources>
    <AdornerDecorator>

        <TabControl SelectedIndex="{Binding TabAccountIndexProperty}">
            <TabItem>

                <TabItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <Image Height="18" Source="/Resources/key.ico" />
                        <TextBlock Margin="5,0,0,0" Text="Login" />

                    </StackPanel>
                </TabItem.Header>


                <AdornerDecorator>
                    <Grid Margin="20"
                          HorizontalAlignment="Center"
                          VerticalAlignment="Top"
                          Background="#FF8AAED4">

                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="200" />
                            <ColumnDefinition Width="40" />



                        </Grid.ColumnDefinitions>
                        <Grid.Resources>
                            <Style TargetType="{x:Type TextBox}">
                                <Setter Property="Margin" Value="0,0,0,1" />
                                <Setter Property="BorderBrush" Value="Azure" />
                                <Setter Property="BorderThickness" Value="1" />
                            </Style>
                            <Style TargetType="{x:Type Label}">
                                <Setter Property="Margin" Value="0,0,0,1" />
                            </Style>
                        </Grid.Resources>
                        <Label Grid.Column="1"
                               Content="Please Login"
                               FontSize="15"
                               FontWeight="Light" />


                        <Label Grid.Row="1"
                               Grid.Column="0"
                               Content="User Name: " />
                        <TextBox Grid.Row="1"
                                 Grid.Column="1"
                                 IsEnabled="{Binding Path=IsLoggedInNeg}"
                                 MaxLength="15"
                                 Style="{StaticResource textBoxInError}"
                                 Text="{Binding CurrentUserLogin.Username,
                                                Mode=TwoWay,
                                                UpdateSourceTrigger=PropertyChanged,
                                                ValidatesOnDataErrors=True,
                                                NotifyOnValidationError=True}"
                                 Validation.ErrorTemplate="{StaticResource validationTemplate}" />

                        <Label Grid.Row="2"
                               Grid.Column="0"
                               Content="Password: " />

                        <PasswordBox Grid.Row="2"
                                     Grid.Column="1"
                                     IsEnabled="{Binding Path=IsLoggedInNeg}"
                                     MaxLength="15"
                                     pswh:PasswordHelper.Attach="True"
                                     pswh:PasswordHelper.Password="{Binding Path=CurrentUserLogin.Password,
                                                                            Mode=TwoWay,
                                                                            UpdateSourceTrigger=PropertyChanged,
                                                                            ValidatesOnDataErrors=True,
                                                                            NotifyOnValidationError=True}"
                                     Style="{StaticResource PasswordBoxInError}"
                                     Validation.ErrorTemplate="{StaticResource validationTemplate}" />

                        <StackPanel Grid.Row="4"
                                    Grid.ColumnSpan="3"
                                    Width="auto"
                                    Height="auto"
                                    HorizontalAlignment="Stretch"
                                    Orientation="Horizontal">
                            <Button Width="170"
                                    HorizontalAlignment="Stretch"
                                    Command="{Binding AuthLoginCommand}"
                                    Content="Login" />
                            <Button Width="170"
                                    HorizontalAlignment="Stretch"
                                    Command="{Binding LogOutCommand}"
                                    Content="Log Out" />

                        </StackPanel>
                    </Grid>
                </AdornerDecorator>
            </TabItem>
            <TabItem IsEnabled="{Binding Path=IsLoggedInNeg}">
                <TabItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <Image Height="18" Source="/Resources/plus.png" />
                        <TextBlock Margin="5,0,0,0" Text="Create Account" />

                    </StackPanel>
                </TabItem.Header>
                <AdornerDecorator>
                    <Grid Margin="20"
                          HorizontalAlignment="Center"
                          VerticalAlignment="Top"
                          Background="#FF8AAED4">

                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="25" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="200" />
                            <ColumnDefinition Width="40" />
                        </Grid.ColumnDefinitions>
                        <Grid.Resources>
                            <Style TargetType="{x:Type TextBox}">
                                <Setter Property="Margin" Value="0,0,0,1" />
                                <Setter Property="BorderBrush" Value="Azure" />
                                <Setter Property="BorderThickness" Value="1" />
                            </Style>
                            <Style TargetType="{x:Type Label}">
                                <Setter Property="Margin" Value="0,0,0,1" />
                            </Style>
                        </Grid.Resources>
                        <Label Grid.Row="0"
                               Grid.Column="1"
                               HorizontalAlignment="Left"
                               Content="Please Create User:"
                               FontSize="15"
                               FontWeight="Light" />

                        <Label Grid.Row="1"
                               Grid.Column="0"
                               Width="80px"
                               Content="User Name: " />
                        <TextBox Grid.Row="1"
                                 Grid.Column="1"
                                 MaxLength="15"
                                 Style="{StaticResource textBoxInError}"
                                 Text="{Binding CurrentUserLogin.Username,
                                                Mode=TwoWay,
                                                UpdateSourceTrigger=PropertyChanged,
                                                ValidatesOnDataErrors=True,
                                                NotifyOnValidationError=True}"
                                 Validation.ErrorTemplate="{StaticResource validationTemplate}" />

                        <Label Grid.Row="2"
                               Grid.Column="0"
                               Width="80px"
                               Content="Password: " />
                        <PasswordBox Grid.Row="2"
                                     Grid.Column="1"
                                     MaxLength="15                                          "
                                     pswh:PasswordHelper.Attach="True"
                                     pswh:PasswordHelper.Password="{Binding Text,
                                                                            Path=CurrentUserLogin.Password,
                                                                            Mode=TwoWay,
                                                                            UpdateSourceTrigger=PropertyChanged,
                                                                            ValidatesOnDataErrors=True,
                                                                            NotifyOnValidationError=True}"
                                     Style="{StaticResource PasswordBoxInError}"
                                     Validation.ErrorTemplate="{StaticResource validationTemplate}" />

                        <Label Grid.Row="3"
                               Grid.Column="0"
                               Width="80"
                               Content="Type:" />
                        <ComboBox Grid.Row="3"
                                  Grid.Column="1"
                                  DisplayMemberPath="Type"
                                  IsSynchronizedWithCurrentItem="True"
                                  ItemsSource="{Binding Path=UserTypes}"
                                  SelectedItem="{Binding Path=SelectedUserType}" />


                        <StackPanel Grid.Row="5"
                                    Grid.ColumnSpan="3"
                                    HorizontalAlignment="Stretch"
                                    Orientation="Horizontal">
                            <Button Width="340"
                                    Command="{Binding CreateUserCommand}"
                                    Content="Create User" />
                        </StackPanel>

                    </Grid>
                </AdornerDecorator>
            </TabItem>
        </TabControl>
    </AdornerDecorator>
</UserControl>
